<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js">/*
 * Copyright (c) 2016 JUI All rights reserved.
 */

;(function () {

<span id='JUI-Common'>    /**
</span>     * 顶级父类,提供一些公共方法
     * @class JUI.Common
     */
    JUI.Class('Common', {
        // 默认属性
        OPTS: {}
<span id='global-method-constructor'>        /**
</span>         * 构造函数
         * @constructor
         * @ignore
         */
        , init: function (opts) {
            this.opts = $.extend({}, this.OPTS, opts);
        }
<span id='JUI-Common-method-getDefOpts'>        /**
</span>         * 返回默认属性
         * @return {Object} 默认属性
         */
        , getDefOpts: function () {
            return this.OPTS;
        }
<span id='JUI-Common-method-opt'>        /**
</span>         * 设置/获取属性
         * @param {String} optName 属性名
         * @param {Object} val 属性值
         */
        , opt: function (optName, val) {
            if (optName &amp;&amp; typeof optName === 'string') {
                if (val !== undefined) {
                    this.opts[optName] = val;
                } else {
                    return this.opts[optName];
                }
            }
        }
<span id='JUI-Common-method-on'>        /**
</span>         * 设置事件
         * @param {String} eventName 事件名,首字母大写
         * @param {Function} fn 事件方法
         */
        , on: function (eventName, fn) {
            this.opt('on' + eventName, fn);
        }
<span id='JUI-Common-method-set'>        /**
</span>         * 设置/获取属性,同opt(optName,val)
         * @param {String} name 属性名
         * @param {Object} val 属性值
         */
        , set: function (name, val) {
            this.opt(name, val);
        }
<span id='JUI-Common-method-getOpts'>        /**
</span>         * 返回属性对象
         * @return {Object}
         */
        , getOpts: function () {
            return this.opts;
        }
<span id='JUI-Common-method-options'>        /**
</span>         * 作用同getOpts()
         */
        , options: function () {
            return this.getOpts();
        }
<span id='JUI-Common-method-fire'>        /**
</span>         * 触发一个事件
         * @param {String} eventName 事件名
         */
        , fire: function (eventName) {
            var eventFun = this.opts['on' + eventName];
            if (eventFun) {
                var argus = [];
                for (var i = 1, len = arguments.length; i &lt; len; i++) {
                    argus.push(arguments[i]);
                }
                return eventFun.apply(this, argus);
            }
        }
<span id='JUI-Common-method-runOptFun'>        /**
</span>         * 运行一个配置参数上的方法
         * var win = new JUI.Win({handler:function(){}});&lt;br&gt;
         * win.runOptFun('handler')
         * @param {String} funName 方法名
         */
        , runOptFun: function (funName) {
            var fun = this.opts[funName];
            if (fun) {
                var argus = [];
                for (var i = 1, len = arguments.length; i &lt; len; i++) {
                    argus.push(arguments[i]);
                }
                return fun.apply(this, argus);
            }
        }

    });

})();</pre>
</body>
</html>
